<?php

namespace App\Repository\Main;

use App\Repository\BaseRepository;
use App\Repository\UpThree\MainOrderRepostition;
use App\Repository\UpThree\MainOrderTwoRepostition;
use App\Repository\UpThree\BigDataRepostition;
use App\Repository\UpThree\GetThreeOrderRepostition;
use App\Repository\UpThree\GetOrderStatusDataRepostition;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use App\Repository\StockMain\StockOrderNewRepostition;


class GetOrderDataRepository extends  BaseRepository
{
  private $log;
  public function __construct()
  {
    $this->log = new Logger('mainGetOrderStatus');
    $this->log->pushHandler(
      (new RotatingFileHandler(storage_path('/logs/mainGetOrderStatus.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
    );
    parent::__construct();
  }
  //异步信息 全部都需要走这个地方 
  public function sendOrder($data = array(), $type = '')
  {
    // 都需要对应成功或失败
    $res = [];
    switch ($type) {
      case 'updateOrderStatus':
        // 订单状态 定时更新
        $model = new GetOrderStatusDataRepostition();
        $res = $model->updateOrderStatus($data);
        break;
      case 'getAllOrderStatus':
        // 启动所有的订单
        $model = new GetOrderStatusDataRepostition();
        $res = $model->getAllOrderStatus($data);
        break;
      case 'getOrderUpOrders':
        // 订单更新  老订单表更新到新订单表  暂不运行
        $model = new GetOrderStatusDataRepostition();
        $model->getOrderUpOrders($data);
        break;
      case 'varOrderUpOrders':
        // 验证老订单表和 新订单表的数据
        $model = new GetOrderStatusDataRepostition();
        $model->varOrderUpOrders($data);
        break;
      case 'douyinPaySyncOrder':
        // 抖音支付
        $model = new GetOrderStatusDataRepostition();
        $res = $model->douyinPaySyncOrder($data);
        break;
      case 'douyinRefundSyncOrder':
        // 抖音小程序 同步订单
        $model = new GetOrderStatusDataRepostition();
        $res = $model->douyinRefundSyncOrder($data);
        break;
      case 'getPddListAll':
        // 抓取拼多多 列表的数据 半个小时一次
        $model = new GetThreeOrderRepostition();
        $res = $model->getPddListAll($data);
        break;
      case 'getPddListAllOne':
        // 抓取单个拼多多应用的 5分钟运行一次  
        $model = new GetThreeOrderRepostition();
        $res = $model->getPddListAllOne($data);
        break;
      case 'sendExpressSms':
        // 发送短信
        if (empty($data['data'])) {
          $res = ['statsu' => 100, 'msg' => '延时发送短信订单参数为空'];
          break;
        }
        if (empty($data['confData'])) {
          $res = ['statsu' => 100, 'msg' => '延时发送短信配置参数为空'];
          break;
        }
        $model = new MainOrderTwoRepostition();
        $datas = $data['data'];
        $resConf = $data['confData'];
        $res = $model->isSmsAndSend($datas, $resConf);
        break;
      case 'expressStatusSendSms':
        // 判断是否延时发送短信
        $model = new MainOrderTwoRepostition();
        $res = $model->expressStatusSendSms($data);
        break;
      case 'backInformat':
        // 延长时间判断是否办理成功
        $model = new StockOrderNewRepostition();
        $res = $model -> backClickId($data);
        break;
      case 'liantongBackApi':
        // 延长时间判断是否办理成功
        $model = new GetThreeOrderRepostition();
        $page = 1;
        if(is_array($data)){
          $page = $data['orderno'];
        }
        $res = $model -> getLianTongBack($page);
        break;
    }
    $this->log->info('类型:' . $type . '参数:' . jsonEncodeMsg($data) . '返回的结果:' . jsonEncodeMsg($res));
    if (empty($res['code']) || $res['code'] != 200) {
      // 这个地方可以重新提交
    }
    return $res;
  }
  // 大文件的读取和设置
  public function longFile($data = array(), $type = '')
  {
  }
}
